//
//  MainTabBar.swift
//  weiboSwift
//
//  Created by 龚欣 on 15/6/24.
//  Copyright © 2015年 gong. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    let btnCount = 5
    override func layoutSubviews() {
        super.layoutSubviews()
        let w = UIScreen.mainScreen().bounds.width/CGFloat(btnCount)
        let rect = CGRectMake(0, 0, w, 49)
        var index : CGFloat = 0
        for view in subviews {
            if view.isKindOfClass(UIControl){
                view.frame = CGRectOffset(rect,index * w, 0)
                
                index += index == 1 ? 2 : 1
            }
        
        }
        composedBtn.frame = CGRectOffset(rect, 2 * w, 0)
        addSubview(composedBtn)
    }
    
    lazy var composedBtn : UIButton = {
        let btn = UIButton(type: UIButtonType.Custom)
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        return btn
        }()

}
